//var api = "http://192.168.8.92:8080/bb/";
var api = "http://118.31.64.230:8080/bb/";
var debug = false;
var Mock = require('mock.js');
//var wxRequest = require('wxRequest.js');
function ajax(data , datas,fn,fa) {
    wx.showLoading({
        title: '加载中',
        mask: true
    })
    if (!debug) {
        //ajax
		var xml = {'X-Requested-With': 'XMLHttpRequestclient'};
		var allData = Object.assign(xml,datas) 
        wx.request({
            url: api + data,
            method: 'get',
			data: allData,
            header: {"content-Type": "application/x-www-form-urlencoded;charset=utf-8"},
            success: res => {
				wx.hideLoading();
                fn(res);
            },
            fail: res => {
                fa => {
					wx.hideLoading();
                    wx.showToast({
                        title: '网络错误',
                        icon: 'none'
                    })
                }
            },
            complete: res => {
                 wx.hideLoading();
            }
        });
    } else {
        //模拟数据
        var res = Mock.mock({
            "jsonMessage": "成功",
            "jsonType": "success",
            "openid": "qcf4q6f4564ew6f54w",
            "index": [{
                "id": "001",
                "title": "入门测试",
                "content": "腹部训练可以有效提高自身睾酮",
                "pay": "免费",
                "image": "../../../utils/images/test1.png"
            }, {
                "id": "002",
                "title": "中级测试",
                "content": "腰部训练可以有效提高自身素质",
                "pay": 10.00,
                "image": "../../../utils/images/test2.png"
            }, {
                "id": "003",
                "title": "高级测试",
                "content": "胳膊训练可以有效提高自身肌肉",
                "pay": 20.00,
                "image": "../../../utils/images/test3.png"
            }],
            "plan": [{
                "id": "004",
                "title": "高级测试",
                "content": "胳膊训练可以有效提高自身肌肉",
                "pay": 20.00,
                "image": "../../../utils/images/test3.png"
            }, {
                "id": "006",
                "title": "高级测试",
                "content": "胳膊训练可以有效提高自身肌肉",
                "pay": "免费",
                "image": "../../../utils/images/test2.png"
            }, {
                "id": "0021",
                "title": "高级测试",
                "content": "胳膊训练可以有效提高自身肌肉",
                "pay": "免费",
                "image": "../../../utils/images/test1.png"
            }],
            "testQuestion": {
                "idd": 1,
                "title": "平时吃饭用什么？",
                "ps": "考察你的反应能力",
                "length": 3,
                "select": [{
                    "id": 1,
                    "image": "../../../utils/images/tran.png",
                    "content": "我用左手吃饭很舒服"
                }, {
                    "id": 2,
                    "image": "../../../utils/images/tran.png",
                    "content": "我用右手吃饭很得劲"
                }, {
                    "id": 3,
                    "image": "../../../utils/images/tran.png",
                    "content": "你们牛逼，我用筷子吃饭"
                }]
            },
            "testQuestion1": {
                "idd": 2,
                "title": "平时走路用什么？",
                "ps": "考察你的速度",
                "select": [{
                    "id": 1,
                    "image": "../../../utils/images/tran.png",
                    "content": "我用自行车"
                }, {
                    "id": 2,
                    "image": "../../../utils/images/tran.png",
                    "content": "我用双腿走"
                }, {
                    "id": 3,
                    "image": "../../../utils/images/tran.png",
                    "content": "我飞着上班"
                }]
            },
            "tranAction": [{
                "title": "上腹训练",
                "text": "因为上半身抬起的力量来源于腹部，而非手臂，所有，一定要避免双手主动拉杆",
                "image": "../../../utils/images/tran.png"
            }, {
                "title": "侧腹训练",
                "text": "因为上半身抬起的力量来源于腹部，而非手臂，所有，一定要避免双手主动拉杆",
                "image": "../../../utils/images/tran.png"
            }, {
                "title": "下腹训练",
                "text": "因为上半身抬起的力量来源于腹部，而非手臂，所有，一定要避免双手主动拉杆",
                "image": "../../../utils/images/tran.png"
            }],
            "message": [{
                "title": "系统通知",
                "time": "2018-07-05",
                "content": "UI晚点回程度分为低级别企鹅窝一的好QUI文化低气温hi确定hi全文打后期维护请问的期望好多群回去武汉地区文化低器我还得企汇网第七代后期的确很我完工后覅我服务不错博UI文本是哦废物不过分哦我无额覅评委会覅我和覅维护发脾气维护费评委会发票违法 去和地区皇帝回去诋毁到期后地址 去玩大号切换去我那都会前往回去我的期望"
            }, {
                "title": "付款通知",
                "time": "2018-07-05",
                "content": "UI晚点回去和地区皇帝回去诋毁到期后地址 去玩大号切换去我那都会前往回去我的期望"
            }, {
                "title": "账户通知",
                "time": "2018-07-05",
                "content": "UI晚点回去和地区皇帝回去诋毁到期后地址 去玩大号切换去我那都会前往回去我的期望"
            }, {
                "title": "拔萝卜通知",
                "time": "2018-07-05",
                "content": "UI晚点回去和地区皇帝回去诋毁到期后地址 去玩大号切换去我那都会前往回去我的期望"
            }],
            "testre": [{
                "title": "入门测试结果",
                "id": 12,
                "time": "2018-07-05",
                "desc": "他可以更好的帮助您"
            }, {
                "title": "中级测试结果",
                "id": 32,
                "time": "2018-07-05",
                "desc": "他可以更好的帮助您"
            }, {
                "title": "高级测试结果",
                "id": 42,
                "time": "2018-07-05",
                "desc": "他可以更好的帮助您"
            }],
            "result": {
                "title": "入门测试",
                "id": 11,
                "data": [{
                    "num": 0,
                    "content": "深蹲时动作",
                    "sresult": "正常",
                    "suggest": [{
                        "advice": "增肌类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }, {
                        "advice": "塑性类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }, {
                        "advice": "奔跑类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }]
                }, {
                    "num": 1,
                    "content": "起立时动作",
                    "sresult": "正常",
                    "suggest": [{
                        "advice": "增肌类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }, {
                        "advice": "塑性类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }, {
                        "advice": "奔跑类方法",
                        "state": 0,
                        "image": "../../../utils/images/tran.png"
                    }]
                }]
            },
            "process": {
                "id": 1,
                "week": [{
                    "weekeend": '第一周',
                    "title": "计划循序渐进",
                    "times": [{
                        "time": "1",
                        "percent": [{
                            "blue": "300",
                        }, {
                            "red": "200",
                        }, {
                            "green": "400"
                        }]
                    }, {
                        "time": "2",
                        "percent": [{
                            "blue": "100",

                        }, {
                            "red": "500",

                        }, {
                            "green": "900"
                        }]
                    }]
                }, {
                    "weekeend": '第二周',
                    "title": "继续向前努力",
                    "times": [{
                        "time": "1",
                        "percent": [{
                            "blue": "300",
                        }, {
                            "red": "200",
                        }, {
                            "green": "400"
                        }]
                    }, {
                        "time": "2",
                        "percent": [{
                            "blue": "100",

                        }, {
                            "red": "500",

                        }, {
                            "green": "900"
                        }]
                    }]
                }]
            },
            "sport": {
                "total": 600,
                "precent": [{
                    "time": 100,
                    "color": "yellow"
                }, {

                    "time": 50,
                    "color": "warn"
                }, {
                    "time": 300,
                    "color": "bg"
                }, {
                    "time": 150,
                    "color": "success"
                }]
            }

        })
        //输出结果
        wx.hideLoading();
        fn(res)
    }
}
module.exports.ajax = ajax